class Documents::PublicationsController < Documents::BaseController

  def index
    @search = Publication.search(params[:search]) # TODO remove tabs, spaces...
    @publications = @search.page(params[:page])
  end

  def show
    @comments = @publication.document.comments
  end

  def new
    @publication = Publication.new
  end

  def create
    @publication = Publication.new(params[:publication])
    @publication.document.user = current_user

    if @publication.save
      flash[:notice] = t('publications.create.success')
      redirect_to :action => :index
    else
      render :action => :new
    end
  end

  def update
    if @publication.update_attributes(params[:publication])
      flash[:notice] = t('publications.update.success')
      redirect_to :action => :index
    else
      render :action => :edit
    end
  end
end